package com.bothin.experiment4.service.impl;

import com.bothin.experiment4.constant.NoticeNumConstant;
import com.bothin.experiment4.dao.NoticeMapper;
import com.bothin.experiment4.model.Notice;
import com.bothin.experiment4.service.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by bothin
 * At 2019/12/20 11:57
 * Description:
 */
@Service
public class NoticeServiceImpl implements INoticeService {
    @Autowired
    private NoticeMapper noticeMapper;
    @Override
    public int findNoticeNumById(int id) {
        Notice notice = noticeMapper.selectByPrimaryKey(id);
        if (notice!=null){
            return notice.getNoticeNum();
        }
        return 0;
    }

    @Override
    public Notice findById(Object id) {
        return noticeMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Notice> findAll() {
        return noticeMapper.selectAll();
    }

    @Override
    @Transactional
    public void deleteById(Object id) {
        noticeMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional
    public void update(Notice notice) {
        noticeMapper.updateByPrimaryKeySelective(notice);
    }

    @Override
    @Transactional
    public void insert(Notice notice) {
        noticeMapper.insert(notice);
    }
}
